﻿using Core.Infrastructure;
using Net.Web.Framework.Mvc.Routes;
using Services.Installation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace Net.Web
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("favicon.ico");
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            
            ///注册路由
            var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>();
            routePublisher.RegisterRoutes(routes);

            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", //参数
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                new[] { "Net.Web.Controllers" }
            );
        }

        protected void Application_Start()
        {
            EngineContext.Initialize(false);
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);

            var installationService = EngineContext.Current.Resolve<IInstallationService>();
            //installationService.InstallData("5ina@mail.com", "zwnaihb", true);

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        }
    }
}